package DiffieHellman;

import org.bouncycastle.math.ec.ECPoint;

import java.math.BigInteger;

public class ECDHexchangeTest {

    private static class TestData {
        private final BigInteger skA;
        private final BigInteger skB;
        private final BigInteger pkA_x;
        private final BigInteger pkA_y;
        private final BigInteger pkB_x;
        private final BigInteger pkB_y;
        private final BigInteger k_x;
        private final BigInteger k_y;

        private TestData(String skA, String skB, String pkA_x, String pkA_y, String pkB_x,
                         String pkB_y, String k_x, String k_y) {
            this.skA = new BigInteger(skA, 16);
            this.skB = new BigInteger(skB, 16);
            this.pkA_x = new BigInteger(pkA_x, 16);
            this.pkA_y = new BigInteger(pkA_y, 16);
            this.pkB_x = new BigInteger(pkB_x, 16);
            this.pkB_y = new BigInteger(pkB_y, 16);
            this.k_x = new BigInteger(k_x, 16);
            this.k_y = new BigInteger(k_y, 16);
        }

        public BigInteger getSkA() {
            return skA;
        }

        public BigInteger getSkB() {
            return skB;
        }

        public BigInteger getPkA_x() {
            return pkA_x;
        }

        public BigInteger getPkA_y() {
            return pkA_y;
        }

        public BigInteger getPkB_x() {
            return pkB_x;
        }

        public BigInteger getPkB_y() {
            return pkB_y;
        }

        public BigInteger getK_x() {
            return k_x;
        }

        public BigInteger getK_y() {
            return k_y;
        }
    }

    public static void main(String[] args) {
        primaryTest();
    }

    private static void primaryTest() {
        TestData[] datas = new TestData[]{
                new TestData("111e32da4d217b865cccb70c847603121eae9bfd95bdf399af626d23c05c742c",
                        "4f593b08c8831a5219c961e1a3406401b20655492e5000b1fb5793241501e931",
                        "843884481073b5ab82c7de3312d3423b55c1aa6de69f88de801332fb57df448",
                        "964b1e3d58ae49663918050801e71c92a3642ea150c347586548da9fa14387222",
                        "5d97d6257591c9262cf62cc3c4e25247c01636ce586f8bd0c989cd9fc47a7155",
                        "24abee582cdd8350db90d53285a0c75bb5af82c1020a8072d71cf18852fe38ce",
                        "48781d2ee37339b5530250586f9ac6afb51912d00b68124b617441b2d8ab249e",
                        "7554de2af69e8701af8a2c049ce8105e19c6cc373f70dfdb00b4b6e27651237f"),
                new TestData("3d54b98f2514bb206d41603321649b4fdfe3a5940d64b463ae8200ff86de9230",
                        "300294bf52c16ee418ee3faec3989623ff42c325f8dda19f49547b9dfbfb66c5",
                        "7d7c6c986b0e50da7bd5b49f1291a76b8a6a3fd92d4157995bf20926025c4c25",
                        "5c485be4c2a645ae8275694043c8dab0a8f8f7f6db6447f0fd5d0b9afe16eece",
                        "3b4d4f83b08d369634ca5838c14d6160029f9510e9998b77205f33c16f55d60",
                        "1e098ab40ecb85ae387270bfddec051c7e4e6fed9801527280f79e2d90af2653",
                        "3b75083d29293d8c163e6c39106603116b4b4dec4aafb37b18ab04169c5eec6a4",
                        "7ef39e1a2cd7e22d3b929017cca998f7c3eea0ca579b86bc133d6c5d88db866"),
                new TestData("59cc5c943c58d670886705b4fc4dcbf5b10ea335140d50b4497d2d1193e44aa8",
                        "74ad38c5a83eaca9e11b6bb71ca34c40a9f2df7ae503b3ec774811e4e987306",
                        "2acf093c5d8aaf6b644d5b47cb538dc3ac308579608c473626d2304177f2c5fe",
                        "072af198832ac4d64b8b2998bba3e5b969c6e209a9f560106690eaa7b7e78677",
                        "303d61f6f52f75f2873527410d97fc6e0258464a968d9d6151d6eb94fb1039cf",
                        "6de5d0c159a26113deacc3eafb4bf622148e9629bf33d1dedf083208163bd9c7",
                        "0384fc0227683f4e0299ae291c20f66592d75d2edaf9ac8b19610e369f48fefa",
                        "773bd11ead413f6e212695eeafd222488d93a2cfbf0b18a6562b4eeaedc22860")
        };

        boolean flag = true;
        for (TestData data : datas) {
            ECDHexchange ecdHexchange = new ECDHexchange();
            flag = ecdHexchange.ECDH(data.getSkA(), data.getSkB());
            if (!flag) break;
        }

        if (flag) {
            System.out.println("primaryTest：测试通过");
        } else {
            System.out.println("primaryTest：测试不通过");
        }

    }
}
